<%@ page import="org.biojava.services.das.dao.RegistryUser" %>
<%@ page import="org.biojava.services.das.registry.UserManager" %>
<%@ page import="org.biojava.services.das.dao.Role" %>
<%@ page import="org.biojava.services.das.dao.RegistryUser" %>
<%@ page import="org.biojava.services.das.dao.ProjectBean"%>

<jsp:useBean id="coord" class="dasregistry.coordBean" scope="page"/>


<% String title="DAS registry - available projects";
   String header = title;
%>

<%@ include file="pagehead.jsp" %>

<%
ProjectBean[] projects= new ProjectBean[0];

String action = request.getParameter("cmd");
if ( action == null)
	action = "all";

if (action.equals("showmine") )
	if ( user != null ) {		
		projects = coord.getProjectsForUser(user);
	}
	else
		projects = coord.getAllProjects();
else 
	projects = coord.getAllProjects();
%>


    
<%  if ( email != null ) {
%><script type="text/javascript">
<!--	
function checkUncheckAll(flag) {
     var theForm = document.getElementById('projectaction');
     var z = 0;
	 for(z=0; z<theForm.length;z++){
      	if(theForm[z].type == 'checkbox' ){
	  		theForm[z].checked = flag;
	  	}
	 }
}

function submitAction(object){
	var pos = object.options[object.selectedIndex].value;
	
	var theForm = document.getElementById('projectaction');
	if ( pos == 'delete' ) {
		var ok = confirmation();
		if ( ok )
			theForm.submit();
	}
	if ( pos == 'add' ) {
		theForm.submit();
	}
	if ( pos == 'edit' ) {
		theForm.submit();
	}
}

function confirmation() {
	var answer = confirm("Are you sure you want to delete these projects?")
	if (answer){
		return true;	
	}
	else{
		return false;
	}
}


//--></script>
<%
} %>
    
<jsp:include page="openwindowscript.jsp" />
    
</head>
<body>
<%@ include file="pagebodystart.jsp" %>

<div id="main">

<% if ( action.equals("showmine") ) {
	%>
[ <a href="listProjects.jsp">list all projects</a> ]
<h2>My projects</h2>


	<% if ( projects.length < 1){
		%>You did not register any project, yet.<% 
	}


} else {%>
<h2>DAS registry - available projects</h2>
<%} %>


<p>
Projects allow to give credits about the <strong>funding of a DAS source</strong>. 
Assigning a DAS source to a project means "This DAS source has been funded by project XXX".
</p>
<p>
We are in the process of talking to DAS client providers to show the project acknowledgments next to a DAS track.
</p>






<% if ( email == null){ %>
<p>
You need to be logged in in order to create a project.
</p>

<%} %>

<%  if ( projects.length > 0 ) { %>
<%@ include file="sangertablestart.jsp" %>


<% if ( email != null ){
%>
<form id="projectaction" name="projectaction" action="ProjectAction" method="POST" >
	
	<tr class="row0top">
	
	<td colspan="4">Select: <a href="#" onClick="checkUncheckAll(true);">All</a>
	<a href="#" onClick="checkUncheckAll(false);">None</a>
	</td>
	
	<td colspan="4" align="right">action
		<select name="action" onChange="submitAction(this.form.action);">
		<option value="">select ...</option>		
		<option value="edit">   edit Project</option>	
		<option value="add">   add DAS sources</option>	
		<option value="delete">   delete</option>	
		</select>
	</td>
	</tr>
	
	<tr class="row0bottom">
<% } else { %>
	<tr class="row0">

<%}


	

if ( user != null ){ %>
<td>&nbsp;</td>
<% } %>
<td>Icon</td>
<td>Info</td>
<td>Name</td>
<td>&nbsp;</td>
<td>Description</td>
<td>Nr DAS sources</td>
<td>Homepage</td>
</tr>
<% 


	
	for (int i=0; i<projects.length;i++){
		ProjectBean p = projects[i];
		RegistryUser owner = p.getOwner();
		if (owner == null)
			owner = new RegistryUser();
		

if (i % 2 != 0) {
%>
<tr class="row1" valign="top">
	<%
	} else {
	%>

<tr class="row2" valign="top">
<%} %>
	
	<% if ( user != null) {
		%><td><% 
		if ( user.equals(owner) ){
			%><input type="checkbox" name="projectID" value="<%=p.getProjectID() %>"/><%
		}
		%></td><% 
	}%>
	<td><a href="showProjectDetails.jsp?project_id=<%=p.getProjectID()%>">
	<img src="ProjectIcon?id=<%=p.getProjectID()%>"/></a>
	</td>
	<td><div title="header=[show project details] body=[<%=p.getDescription() %>]"><a href="showProjectDetails.jsp?project_id=<%=p.getProjectID()%>"> 
				<img src="img/messagebox_info16x16.png" border="0" alt="details"
				onMouseOver="window.status='show project details'; return true;"
				onMouseOut="window.status=' '; return true;"/>
				</a></div></td>
	<td><a href="showProjectDetails.jsp?project_id=<%=p.getProjectID()%>">
	<%=p.getName() %></a></td>
	
	<td><%
	if ( user.equals(owner) ){
		%> <a href="showProjectDetails.jsp?project_id=<%=p.getProjectID()%>">
		<img src="img/kuser.png"/></a><%
	}
	 %></td>
	<td><%=p.getDescription() %></td>
	<td><a href="showProjectDetails.jsp?project_id=<%=p.getProjectID()%>"><%= coord.getNrDasSourcesForProject(p) %></a></td>
	<td><div title="header=[<%=p.getHomepage() %>] body=[open the project homepage in another window]"> 
			<a href="javascript:openWindow('<%=p.getHomepage()%>','',640,480)">go&nbsp;to&nbsp;site</a>
			</div> </td>
	
	</tr>
	<% 
	}
}
%>
</form>
<%@ include file ="sangertableend.jsp" %>

<p/>


<%-- 
<!-- statistics on server -->
< %@taglib uri='/WEB-INF/cewolf.tld' prefix='cewolf' % >
     
   
<jsp:useBean id="projectPieChart" class="org.biojava.services.das.cewolf.ProjectPieChartProvider" scope="session"/>

<cewolf:chart 
    id="pieChart" 
    title="" 
    type="pie" 
    showlegend="false"
    
    >
    <cewolf:data>
        <cewolf:producer id="projectPieChart" usecache="false"/>
    </cewolf:data>
    
</cewolf:chart>

<cewolf:img chartid="pieChart" renderer="cewolf" width="400" height="300">
<cewolf:map 
	linkgeneratorid="projectPieChart"
	useJFreeChartTooltipGenerator="true"	
	/>

</cewolf:img>

<p/>

--%>


</div>
<script src="boxover.js"></script>
<%@ include file="sangerfooter.jsp" %>


